<?php
class Blog extends Mclog {

    public function __construct() {
        parent::__construct();
        $theme = $this->getTheme();
        $this->setTplPath( APP_PATH . "/themes/blog/{$theme}/", APP_TPL . "blog/{$theme}/" );
        $this->themeurl = mc_setting( 'weburl' ) . "/themes/blog/{$theme}";
    }

    public function __destruct() {
        $content = ob_get_clean();
        // 压缩HTML代码
        if ( mc_setting( 'is_formathtml' ) ) {
            $content = str_replace( array( "\r", "\n", "\t", "  " ), "", $content );
        }
        // 启用GZIP压缩
        if ( mc_setting( 'is_gzip' ) && function_exists( 'ob_gzhandler' ) ) {
            ob_start( 'ob_gzhandler' );
        } else {
            ob_start();
        }
        exit( $content );
    }

    /*
     *  返回前台模板目录
     */
    private function getTheme() {
        $theme = mc_setting( 'Theme' );
        if ( mc_setting( 'Theme' ) == 'random' ) {
            $list = mc_list_dir( APP_PATH . "/themes/blog/*" );
            $theme = array_rand( $list, 1 );
        }
        return $theme;
    }
}